//
//  LGCloseAccountController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/27.
//  注销账号

#import "LGCloseAccountController.h"
#import "LGNavigationController.h"
#import "LGLoginViewController.h"
#import "LGNavigationView.h"

@interface LGCloseAccountController ()
/**   */
@property (nonatomic , strong)UIScrollView *scrollView;
/**   */
@property (nonatomic , strong)UIView *topView;
/**   */
@property (nonatomic , strong)UIImageView *topIcon;
/**   */
@property (nonatomic , strong)UILabel *topLabel;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UIButton *agreeBtn;
/**   */
@property (nonatomic , strong)UILabel *agreeLabel;
/**   */
@property (nonatomic , strong)UIButton *actionBtn;
@end

@implementation LGCloseAccountController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createSubView];
}

-(void)backBtnAction{
    [self.navigationController popViewControllerAnimated:YES];
}
//阅读须知
-(void)agreeBtnAction:(UIButton *)sender{
    sender.selected = !sender.selected;
}
//注销账号
-(void)destroyAccountAction{
    if (self.agreeBtn.selected == YES) {
        [LGAlertTool alertWithTitle:@"提示" content:@"一旦账号被注销后，您将无法使用此账号登录使用本平台，原先的数据将被全部清空且不可恢复，请谨慎操作" sureTitle:@"仍要注销" sureAction:^{
            [RequestUtil withPOST:@"/doctor/User/destroy" parameters:@{} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
                if(code == 200){
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"islogin"];
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"usersign"];
                    LGNavigationController *navController = [[LGNavigationController alloc]initWithRootViewController:[[LGLoginViewController alloc] init]];
                    [UIApplication sharedApplication].keyWindow.rootViewController = navController;
                }else{
                    [TooltipView showMessage:message offset:0];
                }
            } error:^(NSError *error) {
                [TooltipView showMessage:LGErrorMessage offset:0];
            }];
        }];
    }else{
        [TooltipView showMessage:@"请先阅读并同意《注销账号须知》" offset:0];
    }
    
}
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleDefault;
}
-(void)createSubView{
    self.title = @"注销账号";
    [self.view addSubview:self.scrollView];
    [self.scrollView addSubview:self.topView];
    [self.scrollView addSubview:self.topIcon];
    [self.scrollView addSubview:self.topLabel];
    [self.scrollView addSubview:self.titleLabel];
    [self.scrollView addSubview:self.contentLabel];
    [self.view addSubview:self.agreeBtn];
    [self.view addSubview:self.agreeLabel];
    [self.view addSubview:self.actionBtn];
    //CGRectMake(viewPix(12), kMaxY(self.titleLabel.frame)+viewPix(12), Screen_W-viewPix(30), viewPix(800))
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(12));
        make.left.equalTo(self.view).offset(viewPix(12));
        make.right.equalTo(self.view).offset(-viewPix(18));
    }];
    CGFloat height = [self.contentLabel.text textHeightWithFont:LGFont(14) maxWidth:Screen_W-viewPix(31)]+150;
    self.scrollView.contentSize = CGSizeMake(Screen_W, viewPix(100)+height);
}


-(UIScrollView *)scrollView{
    if(!_scrollView){
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight-bottomSafeBarHeight/2.0-viewPix(100))];
        _scrollView.contentSize = CGSizeMake(Screen_W, Screen_H);
    }
    return _scrollView;
}

-(UIView *)topView{
    if(!_topView){
        _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(46))];
        _topView.backgroundColor = [UIColor colorWithString:@"#FAD7D5"];
      
    }
    return _topView;
}

-(UIImageView *)topIcon{
    if(!_topIcon){
        _topIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"注销须知-注意"]];
        _topIcon.frame = CGRectMake(viewPix(12), viewPix(9), viewPix(12), viewPix(12));
    }
    return _topIcon;
}

-(UILabel *)topLabel{
    if(!_topLabel){
        _topLabel = [UILabel lableWithText:@"注销前需要先阅读并同意账号注销须知，一旦注销所有与账号相关的信息将无法恢复" colorString:@"#FA5151" textFont:LGFont(12) textAlignment:NSTextAlignmentLeft lines:2];
        _topLabel.frame = CGRectMake(viewPix(28), viewPix(6), Screen_W-viewPix(35), viewPix(34));
        [_topLabel lineSpacing:3];
    }
    return _topLabel;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"《账号注销须知》" colorString:@"#000000" textFont:LGFont(14) textAlignment:NSTextAlignmentCenter lines:1];
        _titleLabel.frame = CGRectMake(0, kMaxY(self.topView.frame)+viewPix(12), Screen_W, viewPix(23));
    }
    return _titleLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"亲爱的平台用户：\n\n一、如果您确定需要注销账号，您的账号须同时满足以下条件：\n\n（1）为确保注销系您本人进行的操作，防止第三人在篡改密码后注销您的账号，需确保在最近一个月内，您的账号没有进行更改密码、找回密码、更改绑定手机等敏感操作；\n\n（2）账号内无未完成的订单和服务；\n\n（3）账号无任何纠纷，包括服务争议和投诉举报记录；\n\n二、注销本账号后，您将自愿放弃以下权益和资产：\n\n（1）包括但不限于账号信息、患者信息、订单信息、与患者的沟通记录等数据；\n\n（2）包括但不限于已产生的签约审核、专家咨询、视频咨询等服务收益；\n\n三、账号一旦被注销，数据将被全部清空且不可恢复，请谨慎操作。\n\n四、如有需要，请在操作之前自行备份相关信息和数据。因账号注销对用户造成的不利影响，本平台将不承担任何责任。"colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:0];
//        _contentLabel.frame = CGRectMake(viewPix(12), kMaxY(self.titleLabel.frame)+viewPix(12), Screen_W-viewPix(30), viewPix(800));
        [_contentLabel lineSpacing:5];
    }
    return _contentLabel;
}

-(UIButton *)agreeBtn{
    if(!_agreeBtn){
        _agreeBtn = [UIButton buttonWithTitle:@"我已阅读并同意" titleFont:LGFont(14) textColor:@"#888888" imageName:@"注销须知-未读"];
        [_agreeBtn setImage:[UIImage imageNamed:@"注销须知-已读"] forState:UIControlStateSelected];
        _agreeBtn.frame = CGRectMake(viewPix(40), kMaxY(self.scrollView.frame)+viewPix(5), viewPix(150), viewPix(20));
        _agreeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _agreeBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
        [_agreeBtn addTarget:self action:@selector(agreeBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _agreeBtn;
}

-(UILabel *)agreeLabel{
    if(!_agreeLabel){
        _agreeLabel = [UILabel lableWithText:@"《注销账号须知》" colorString:@"#FA5151" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        _agreeLabel.frame = CGRectMake(kMaxX(self.agreeBtn.frame), kMinY(self.agreeBtn.frame), viewPix(150), viewPix(20));
    }
    return _agreeLabel;
}

-(UIButton *)actionBtn{
    if(!_actionBtn){
        _actionBtn = [UIButton buttonWithTitle:@"注销账号" titleFont:LGFontWeight(14, UIFontWeightSemibold) textColor:@"#FFFFFF" imageName:@""];
        _actionBtn.frame = CGRectMake(viewPix(33), kMaxY(self.agreeLabel.frame)+viewPix(10), Screen_W-viewPix(66), viewPix(44));
        _actionBtn.backgroundColor = [UIColor colorWithString:@"#FA5151"];
        _actionBtn.cornerRidus = viewPix(22);
        [_actionBtn addTarget:self action:@selector(destroyAccountAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _actionBtn;
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
